import { DataTypes } from "sequelize";
import sequelize from "../database/index.js";

const User = sequelize.define(
  "User",
  {
    user_id: {
      type: DataTypes.INTEGER,
      autoIncrement: true,
      primaryKey: true,
      comment: "用户ID，主键，自增",
    },
    username: {
      type: DataTypes.STRING(50),
      allowNull: false,
      unique: true,
      comment: "用户名，唯一",
    },
    password_hash: {
      type: DataTypes.STRING(255),
      allowNull: false,
      comment: "密码哈希值",
    },
    email: {
      type: DataTypes.STRING(100),
      unique: true,
      comment: "用户邮箱，唯一",
    },
    profile_picture: {
      type: DataTypes.STRING(255),
      comment: "头像URL",
    },
    bio: {
      type: DataTypes.TEXT,
      comment: "个人简介",
    },
    phone: {
      type: DataTypes.STRING(20),
      comment: "手机号",
      field: "extension", // 指定数据库中的字段名
    },
  },
  {
    tableName: "users",
    timestamps: true,
    createdAt: "created_at", // 自定义创建时间字段
    updatedAt: "updated_at", // 自定义更新时间字段
    comment: "用户表，存储用户的基本信息",
  }
);

export default User;
